/*
 * @Description:
 * @Version: V1.0
 * @Author: zw_1520@163.com
 * @Date: 2024-09-04 14:12:57
 * @LastEditors: zw_1520@163.com
 * @LastEditTime: 2025-05-14 19:09:15
 * Copyright (C) All rights reserved.
 */

#include "robot_hardware_api.h"

bool Robot::robotNaviControl(double x, double y, double yaw) {
  // Constructs robot enable message
  std::string robot_enable_message;
  Json::FastWriter fw;
  Json::Value root;

  root["msg_id"] = "1001";
  root["msg_name"] = "robot_task_control";
  root["from"] = "safe_check_service";
  root["to"] = "robot";
  root["parameters"]["task_type"] = "navi";
  root["parameters"]["x"] = x;
  root["parameters"]["y"] = y;
  root["parameters"]["yaw"] = yaw;

  robot_enable_message = fw.write(root);
  std::cout << "robot_navi_message: " << robot_enable_message << std::endl;
  client_->SendData("1001", robot_enable_message);
  return true;
}

bool Robot::robotTtsControl(std::string tts_value) {
  // Constructs robot enable message
  std::string robot_enable_message;
  Json::FastWriter fw;
  Json::Value root;

  root["msg_id"] = "1001";
  root["msg_name"] = "robot_task_control";
  root["from"] = "safe_check_service";
  root["to"] = "robot";
  root["parameters"]["task_type"] = "tts";
  root["parameters"]["tts_value"] = tts_value;

  robot_enable_message = fw.write(root);
  std::cout << "robot_tts_message: " << robot_enable_message << std::endl;
  client_->SendData("1001", robot_enable_message);
  return true;
}

bool Robot::robotPlayMotion(std::string motion_id) {
  // Constructs robot enable message
  std::string play_motion_message;
  Json::FastWriter fw;
  Json::Value root;

  root["msg_id"] = "1001";
  root["msg_name"] = "robot_task_control";
  root["from"] = "safe_check_service";
  root["to"] = "robot";
  root["parameters"]["task_type"] = "play_motion";
  root["parameters"]["motion_id"] = motion_id;

  play_motion_message = fw.write(root);
  std::cout << "robot_play_motion_message: " << play_motion_message
            << std::endl;
  client_->SendData("1001", play_motion_message);
  return true;
}

bool Robot::robotNavigation(int point_id) {
  // Constructs robot enable message
  std::string robot_navi_message;
  Json::FastWriter fw;
  Json::Value root;

  root["msg_id"] = "1001";
  root["msg_name"] = "robot_task_control";
  root["from"] = "safe_check_service";
  root["to"] = "robot";
  root["parameters"]["task_type"] = "navigation";
  root["parameters"]["poi"]["point_id"] = point_id;

  robot_navi_message = fw.write(root);
  std::cout << "robot_navi_message: " << robot_navi_message << std::endl;
  client_->SendData("1001", robot_navi_message);
  return true;
}